package com.youshang520i.demo;

import org.springframework.context.annotation.*;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * 描述信息
 *
 * @author hardy
 * @date 2021/2/22 15:06
 */
public class OnBeanCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(LocalConditionalOnBean.class.getName());
        if (null == annotationAttributes) {
            return false;
        }
        String beanName = (String) annotationAttributes.get("value");
        //判断当前容器中的bean是否存在
        return context.getBeanFactory().containsBean(beanName);
    }

//  @Override
//  public ConfigurationPhase getConfigurationPhase() {
//    return ConfigurationPhase.REGISTER_BEAN;
//  }
}
